# 编程实现中值降噪、直方图统计、直方图均衡化和局部自适应直方图均衡化，并输出相关结果

# # 直方图统计
# import numpy as np
# import  cv2 as cv
# from matplotlib import  pyplot as plt
#
# img = cv.imread('./picture/lena.jpg',0)
# histr = cv.calcHist([img],[0],None,[256],[0,256])
# plt.subplot(121),plt.imshow(img,'gray')
# plt.title('originall'),plt.xticks([]),plt.yticks([])
# plt.subplot(122)
# plt.title('hist')
# plt.plot(histr,color='gray')
# plt.xlim([0,256])
# plt.show()

# 直方图均衡化
# 案例
# import  cv2
# from matplotlib import  pyplot as plt
#
# img = cv2.imread('./picture/test.jpg',0)
# hist = cv2.calcHist([img],[0],None,[256],[0,256])
# # hist是一个256*1的数组，每一个值代表了与此灰度值对应的像素点的
#
# plt.hist(img.ravel(),256);
# plt.show()







# # 直方图均衡化 局部自适应直方图均衡化
# import cv2 as cv
#
# src = cv.imread("./picture/tsukuba.jpg")
#
#
# # 1. 全局直方图均衡化
# def globalEqualHist(image):
#     # 如果想要对图片做均衡化，必须将图片转换为灰度图像
#     gray = cv.cvtColor(image, cv.COLOR_BGR2GRAY)
#     dst = cv.equalizeHist(gray)  # 在说明文档中有相关的注释与例子
#     # equalizeHist(src, dst=None)函数只能处理单通道的数据,src为输入图像对象矩阵，必须为单通道的uint8类型的矩阵数据
#     # dst: 输出图像矩阵(src的shape一样)
#     cv.imshow("Global equalizeHist", dst)
#     # print(len(image.shape))  # 彩色图像的shape长度为3
#     # print(len(gray.shape))  # 灰度图像的shape长度为2
#     # print(gray.shape)   # 灰度图像只有高、宽
#
#
# def localEqualHist(image):
#     gray = cv.cvtColor(image, cv.COLOR_BGR2GRAY)
#     clahe = cv.createCLAHE(clipLimit=5, tileGridSize=(7,7))
#     dst = clahe.apply(gray)
#     cv.imshow("clahe image", dst)
#
# globalEqualHist(src)
# # localEqualHist(src)
# cv.imshow("original image", src)
# cv.waitKey(0)
# cv.destroyAllWindows()







